package fr.channel.client;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.place.shared.PlaceHistoryHandler;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;

import fr.channel.client.place.ConnectionPlace;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ChannelTest implements EntryPoint {

	private static VerticalPanel logPanel = new VerticalPanel();
	
	/**
	 * This is the entry point method.
	 */
	public final void onModuleLoad() {
		MainGinjector ginjector = GWT.create(MainGinjector.class);
		SimplePanel contentWrapper = new SimplePanel();
		EventBus eventBus = ginjector.getEventBus();
		
		ActivityManager activityManager = new ActivityManager(ginjector.getActivityMapper(), eventBus);
		activityManager.setDisplay(contentWrapper);

        PlaceHistoryHandler historyHandler = new PlaceHistoryHandler(ginjector.getPlaceHistoryMapper());
        historyHandler.register(ginjector.getPlaceController(), eventBus, new ConnectionPlace());
		
		RootPanel.get("mainPanel").add(contentWrapper);
		RootPanel.get("logPanel").add(logPanel);
		historyHandler.handleCurrentHistory();
		log("Demarrage Ok");
	}
	
	public static  void log(final String message) {
		logPanel.add(new HTML(message));
	}
}
